package com.hsc.yalebao.tabChongZhi;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.DrawableTypeRequest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.google.gson.Gson;
import com.hsc.yalebao.base.ActivityStack;
import com.hsc.yalebao.base.BaseActivity;
import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.base.MainActivity;
import com.hsc.yalebao.http.AppConstants;
import com.hsc.yalebao.http.HtmlService;
import com.hsc.yalebao.http.RequestNet;
import com.hsc.yalebao.model.PayResultBean;
import com.hsc.yalebao.model.PayTypeBean;
import com.hsc.yalebao.model.ReChargeBaseData;
import com.hsc.yalebao.model.UserBaseBean;
import com.hsc.yalebao.tools.QRCodeUtil;
import com.hsc.yalebao.tools.UiUtil;
import com.hsc.yalebao.weight.LogUtils;
import com.hsc.yalebao.weight.MyDialog1;
import com.hsc.yalebao.weight.MyDialogCancelAndOk;
import com.zhy.http.okhttp.callback.BitmapCallback;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Date;
import java.util.HashMap;

import okhttp3.Call;

import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class WeixinCodeActivity extends BaseActivity {
    private static Context context;
    private static File myCaptureFile;
    private String TAG = "WeixinCodeActivity";
    private String guid = "";
    private Handler handler = new Handler() {
        public void handleMessage(Message paramAnonymousMessage) {
            switch (paramAnonymousMessage.what) {
                default:
                    return;
                case 3:
                    WeixinCodeActivity.this.dismissLoadingDialog();
                    Glide.with(WeixinCodeActivity.context).load(paramAnonymousMessage.obj).placeholder(2130837797).crossFade().into(WeixinCodeActivity.this.mCodeImageView);
                    WeixinCodeActivity.this.mNowChongzhiView.setEnabled(true);
                    WeixinCodeActivity.this.mHasChongzhiView.setEnabled(true);
                    return;
                case 2:
                    WeixinCodeActivity.this.dismissLoadingDialog();
                    Bitmap localBitmap = QRCodeUtil.createImage(paramAnonymousMessage.obj, 300, 300, null);
                    if (localBitmap != null) {
                        WeixinCodeActivity.this.mCodeImageView.setImageBitmap(localBitmap);
                        WeixinCodeActivity.this.mNowChongzhiView.setEnabled(true);
                        WeixinCodeActivity.this.mHasChongzhiView.setEnabled(true);
                        return;
                    }
                    WeixinCodeActivity.this.myDialog1.setMessage("网络繁忙，请稍后再试");
                    WeixinCodeActivity.this.myDialog1.btn_confirm.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View paramAnonymous2View) {
                            CustomApplication.app.finishActivity(WeixinCodeActivity.this);
                        }
                    });
                    WeixinCodeActivity.this.myDialog1.show();
                    return;
                case 1:
                    WeixinCodeActivity.this.dismissLoadingDialog();
                    WeixinCodeActivity.this.myDialog1.setMessage("网络繁忙，请稍后再试");
                    WeixinCodeActivity.this.myDialog1.btn_confirm.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View paramAnonymous2View) {
                            CustomApplication.app.finishActivity(WeixinCodeActivity.this);
                        }
                    });
                    WeixinCodeActivity.this.myDialog1.show();
                    return;
                case 0:
            }
            String str1 = (String) paramAnonymousMessage.obj;
            WeixinCodeActivity.this.dismissLoadingDialog();
            Elements localElements = Jsoup.parse(str1).select("img");
            WeixinCodeActivity.this.isUseful = false;
            for (int i = 0; ; i++) {
                if (i >= localElements.size()) {
                    if (WeixinCodeActivity.this.isUseful)
                        break;
                    WeixinCodeActivity.this.myDialog1.setMessage("网络繁忙，请稍后再试");
                    WeixinCodeActivity.this.myDialog1.btn_confirm.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View paramAnonymous2View) {
                            CustomApplication.app.finishActivity(WeixinCodeActivity.this);
                        }
                    });
                    WeixinCodeActivity.this.myDialog1.show();
                    return;
                }
                String str2 = localElements.get(i).attr("src");
                if (str2.contains("?")) {
                    str2.split("\\?")[0];
                    System.out.println("#################################" + str2);
                    if (str2.contains("http://wytj.9vpay.com/MakeQRCode.aspx")) {
                        WeixinCodeActivity.this.isUseful = true;
                        RequestNet.bindImageToView(str2, WeixinCodeActivity.context, new BitmapCallback() {
                            public void onError(Call paramAnonymous2Call, Exception paramAnonymous2Exception) {
                                WeixinCodeActivity.this.dismissLoadingDialog();
                                LogUtils.e(WeixinCodeActivity.this.TAG, "loadImage-访问失败");
                            }

                            public void onResponse(Bitmap paramAnonymous2Bitmap) {
                                LogUtils.d(WeixinCodeActivity.this.TAG, "下载图像成功");
                                if (paramAnonymous2Bitmap != null) {
                                    WeixinCodeActivity.this.dismissLoadingDialog();
                                    WeixinCodeActivity.this.mNowChongzhiView.setEnabled(true);
                                    WeixinCodeActivity.this.mHasChongzhiView.setEnabled(true);
                                    WeixinCodeActivity.this.mCodeImageView.setImageBitmap(paramAnonymous2Bitmap);
                                    return;
                                }
                                LogUtils.e(WeixinCodeActivity.this.TAG, "图像bitmap==null");
                            }
                        });
                    }
                    if ((str2.contains("http://pan.baidu.com/share/qrcode")) || (str2.contains("http://wx.aishundianzi.com/qr.aspx"))) {
                        WeixinCodeActivity.this.isUseful = true;
                        RequestNet.bindImageToView(str2, WeixinCodeActivity.context, new BitmapCallback() {
                            public void onError(Call paramAnonymous2Call, Exception paramAnonymous2Exception) {
                                WeixinCodeActivity.this.dismissLoadingDialog();
                                LogUtils.e(WeixinCodeActivity.this.TAG, "loadImage-访问失败");
                            }

                            public void onResponse(Bitmap paramAnonymous2Bitmap) {
                                LogUtils.d(WeixinCodeActivity.this.TAG, "下载图像成功");
                                if (paramAnonymous2Bitmap != null) {
                                    WeixinCodeActivity.this.dismissLoadingDialog();
                                    WeixinCodeActivity.this.mNowChongzhiView.setEnabled(true);
                                    WeixinCodeActivity.this.mHasChongzhiView.setEnabled(true);
                                    WeixinCodeActivity.this.mCodeImageView.setImageBitmap(paramAnonymous2Bitmap);
                                    return;
                                }
                                LogUtils.e(WeixinCodeActivity.this.TAG, "图像bitmap==null");
                            }
                        });
                    }
                }
            }
        }
    };
    private boolean isUseful = false;
    private ImageView iv_title_right;
    private ImageView mCodeImageView;
    private ImageView mHasChongzhiView;
    private TextView mMoneyTv;
    private ImageView mNowChongzhiView;
    private TextView mOrderNumTv;
    private PayTypeBean mPayTypeBean;
    private ImageView mPreView;
    private ReChargeBaseData mReChargeBaseData;
    private int memberid;
    private String money;
    private MyDialog1 myDialog1;
    private MyDialogCancelAndOk myDialogCancelAndOk;
    View.OnClickListener onClickListener = new View.OnClickListener() {
        public void onClick(View paramAnonymousView) {
            switch (paramAnonymousView.getId()) {
                case 2131099704:
                default:
                    return;
                case 2131099699:
                    CustomApplication.app.finishActivity(WeixinCodeActivity.this);
                    return;
                case 2131100381:
                    CustomApplication.app.finishActivity(WeixinCodeActivity.this);
                    return;
                case 2131100382:
                    if (WeixinCodeActivity.this.myDialogCancelAndOk == null) {
                        WeixinCodeActivity.this.myDialogCancelAndOk = new MyDialogCancelAndOk(WeixinCodeActivity.this);
                        if ((!"6".equals(WeixinCodeActivity.this.paytype)) && (!"10".equals(WeixinCodeActivity.this.paytype)) && (!"13".equals(WeixinCodeActivity.this.paytype)) && (!"15".equals(WeixinCodeActivity.this.paytype)) && (!"17".equals(WeixinCodeActivity.this.paytype)) && (!"19".equals(WeixinCodeActivity.this.paytype)) && (!"21".equals(WeixinCodeActivity.this.paytype)) && (!"23".equals(WeixinCodeActivity.this.paytype)) && (!"25".equals(WeixinCodeActivity.this.paytype)))
                            break label286;
                        WeixinCodeActivity.this.myDialogCancelAndOk.setMessage("将为您保存二维码并打开微信，是否立即充值?");
                    }
                    while (true) {
                        WeixinCodeActivity.this.myDialogCancelAndOk.btn_confirm.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View paramAnonymous2View) {
                                WeixinCodeActivity.this.saveCroppedImage();
                            }
                        });
                        WeixinCodeActivity.this.myDialogCancelAndOk.show();
                        return;
                        label286:
                        if (("7".equals(WeixinCodeActivity.this.paytype)) || ("9".equals(WeixinCodeActivity.this.paytype)) || ("12".equals(WeixinCodeActivity.this.paytype)) || ("14".equals(WeixinCodeActivity.this.paytype)) || ("16".equals(WeixinCodeActivity.this.paytype)) || ("18".equals(WeixinCodeActivity.this.paytype)) || ("20".equals(WeixinCodeActivity.this.paytype)) || ("22".equals(WeixinCodeActivity.this.paytype)) || ("24".equals(WeixinCodeActivity.this.paytype)))
                            WeixinCodeActivity.this.myDialogCancelAndOk.setMessage("将为您保存二维码并打开支付宝，是否立即充值?");
                    }
                case 2131100383:
            }
            WeixinCodeActivity.this.getStatus();
        }
    };
    private String paytype = "6";
    private TextView tv_miaoshu;
    private TextView tv_title;

    private void getStatus() {
        HashMap localHashMap = new HashMap();
        localHashMap.put("memberid", this.memberid);
        localHashMap.put("orderid", this.mReChargeBaseData.getResult());
        LogUtils.e(this.TAG, "guid" + this.guid);
        LogUtils.e(this.TAG, "client_Ip" + CustomApplication.app.NetIP);
        setBtnIsEnable(false);
        showLoadingDialog();
        RequestNet.get(context, AppConstants.URL_GET_RECHARGE_STATUS, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                WeixinCodeActivity.this.setBtnIsEnable(true);
                WeixinCodeActivity.this.dismissLoadingDialog();
                LogUtils.e("获取失败", "getPay()-result:" + paramAnonymousException);
            }

            public void onResponse(String paramAnonymousString) {
                WeixinCodeActivity.this.setBtnIsEnable(true);
                WeixinCodeActivity.this.dismissLoadingDialog();
                LogUtils.d(WeixinCodeActivity.this.TAG, "result:" + paramAnonymousString);
                if (UiUtil.IsValueEmpty(paramAnonymousString))
                    LogUtils.d(WeixinCodeActivity.this.TAG, "result为空");
                PayResultBean localPayResultBean;
                do
                    while (true) {
                        return;
                        Gson localGson = new Gson();
                        try {
                            localPayResultBean = (PayResultBean) localGson.fromJson(paramAnonymousString, PayResultBean.class);
                            if (localPayResultBean == null) {
                                LogUtils.e(WeixinCodeActivity.this.TAG, "获取失败");
                                return;
                            }
                        } catch (Exception localException) {
                            while (true) {
                                localException.printStackTrace();
                                localPayResultBean = null;
                            }
                            if (localPayResultBean.getFlag() == -4) {
                                WeixinCodeActivity.activityStack.backToMain(MainActivity.class, WeixinCodeActivity.context);
                                return;
                            }
                            if (localPayResultBean.getFlag() == 0) {
                                String str = localPayResultBean.getMsg();
                                if (str.contains("充值中")) {
                                    WeixinCodeActivity.this.ShowDialog1(str);
                                    return;
                                }
                                if (str.contains("充值失败"))
                                    WeixinCodeActivity.this.startActivity(new Intent(WeixinCodeActivity.context, WeixinFailActivity.class));
                            } else {
                                if (localPayResultBean.getFlag() == -2) {
                                    WeixinCodeActivity.this.showDownWireDialog();
                                    return;
                                }
                                if (localPayResultBean.getFlag() == -3) {
                                    WeixinCodeActivity.this.ShowFengjinDialog();
                                    return;
                                }
                            }
                        }
                    }
                while (localPayResultBean.getFlag() != 1);
                Intent localIntent = new Intent(WeixinCodeActivity.this, WeixinResultActivity.class);
                localIntent.putExtra("money", WeixinCodeActivity.this.money);
                WeixinCodeActivity.this.startActivity(localIntent);
                WeixinCodeActivity.activityStack.backTo(MainActivity.class);
            }
        });
    }

    private void init() {
        this.myDialog1 = new MyDialog1(context);
        this.tv_title = ((TextView) findViewById(2131099849));
        this.tv_miaoshu = ((TextView) findViewById(2131099845));
        this.mCodeImageView = ((ImageView) findViewById(2131100380));
        this.mOrderNumTv = ((TextView) findViewById(2131100379));
        this.mMoneyTv = ((TextView) findViewById(2131100314));
        this.mPreView = ((ImageView) findViewById(2131100381));
        this.mNowChongzhiView = ((ImageView) findViewById(2131100382));
        this.mHasChongzhiView = ((ImageView) findViewById(2131100383));
        this.mPreView.setOnClickListener(this.onClickListener);
        this.mNowChongzhiView.setOnClickListener(this.onClickListener);
        this.mHasChongzhiView.setOnClickListener(this.onClickListener);
        this.mOrderNumTv.setText(this.mReChargeBaseData.getResult());
        this.mMoneyTv.setText(this.money);
        this.mNowChongzhiView.setEnabled(false);
        this.mHasChongzhiView.setEnabled(false);
    }

    private void saveCroppedImage() {
        this.mCodeImageView.setDrawingCacheEnabled(true);
        Bitmap localBitmap = this.mCodeImageView.getDrawingCache();
        try {
            File localFile1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/pic/");
            String str = localFile1 + "wx_" + new Date().getTime() + ".png";
            File localFile2 = new File(str);
            if (!localFile1.exists())
                localFile1.mkdirs();
            if (!localFile2.exists())
                localFile2.createNewFile();
            FileOutputStream localFileOutputStream = new FileOutputStream(new File(str));
            localBitmap.compress(Bitmap.CompressFormat.JPEG, 50, localFileOutputStream);
            localFileOutputStream.flush();
            localFileOutputStream.close();
            this.mCodeImageView.setDrawingCacheEnabled(false);
            sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(localFile2)));
            Toast.makeText(this, "保存成功", 0).show();
            if ((!this.paytype.equals("6")) && (!this.paytype.equals("10")) && (!this.paytype.equals("13")) && (!this.paytype.equals("15")) && (!this.paytype.equals("17")) && (!this.paytype.equals("19")) && (!this.paytype.equals("21")) && (!this.paytype.equals("23")))
                if (!this.paytype.equals("25"))
                    break label417;
        } catch (IOException localIOException) {
            while (true) {
                try {
                    Intent localIntent = new Intent();
                    ComponentName localComponentName = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
                    localIntent.setAction("android.intent.action.MAIN");
                    localIntent.addCategory("android.intent.category.LAUNCHER");
                    localIntent.addFlags(268435456);
                    localIntent.setComponent(localComponentName);
                    startActivityForResult(localIntent, 0);
                    this.myDialogCancelAndOk.dismiss();
                    return;
                    localIOException = localIOException;
                    localIOException.printStackTrace();
                } catch (Exception localException1) {
                    UiUtil.showToast(context, "无法跳转到微信，请检查您是否安装了微信！");
                    continue;
                }
                label417:
                if ((this.paytype.equals("7")) || (this.paytype.equals("9")) || (this.paytype.equals("12")) || (this.paytype.equals("14")) || (this.paytype.equals("16")) || (this.paytype.equals("18")) || (this.paytype.equals("20")) || (this.paytype.equals("22")) || (this.paytype.equals("24")))
                    try {
                        startActivity(getPackageManager().getLaunchIntentForPackage("com.eg.android.AlipayGphone"));
                    } catch (Exception localException2) {
                        UiUtil.showToast(context, "无法跳转到支付宝，请检查您是否安装了支付宝！");
                    }
            }
        }
    }

    private void setBtnIsEnable(boolean paramBoolean) {
        if (paramBoolean)
            this.mHasChongzhiView.setImageResource(2130837612);
        while (true) {
            this.mHasChongzhiView.setEnabled(paramBoolean);
            return;
            this.mHasChongzhiView.setImageResource(2130838112);
        }
    }

    @TargetApi(19)
    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(2130903231);
        context = this;
        Bundle localBundle = getIntent().getExtras();
        if (localBundle != null) {
            this.mReChargeBaseData = ((ReChargeBaseData) localBundle.getSerializable("result"));
            this.money = localBundle.getString("money");
            this.paytype = localBundle.getString("paytype");
            this.mPayTypeBean = ((PayTypeBean) localBundle.getSerializable("payTypeBean"));
        }
        if (CustomApplication.app.userBaseBean != null) {
            this.memberid = CustomApplication.app.userBaseBean.getMemberid();
            this.guid = CustomApplication.app.userBaseBean.getGuid();
        }
        init();
        if (("6".equals(this.paytype)) || ("10".equals(this.paytype)) || ("13".equals(this.paytype)) || ("15".equals(this.paytype)) || ("17".equals(this.paytype)) || ("19".equals(this.paytype)) || ("21".equals(this.paytype)) || ("23".equals(this.paytype)) || ("25".equals(this.paytype))) {
            setTitle(8, 0, 2130837809, "微信充值", 0, 8, 8, 0, true);
            this.tv_title.setText("微信支付扫码信息:");
            this.tv_miaoshu.setText(2131296496);
        }
        while (true) {
            showLoadingDialog();
            new Thread() {
                public void run() {
                    super.run();
                    Message localMessage = WeixinCodeActivity.this.handler.obtainMessage();
                    String str = "";
                    try {
                        str = HtmlService.getHtml(WeixinCodeActivity.this.mReChargeBaseData.getPayurl());
                        System.out.println(WeixinCodeActivity.this.mReChargeBaseData.getPayurl() + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" + str + "----------------");
                        if ((str == null) || (str.equals(""))) ;
                        for (localMessage.what = 1; ; localMessage.what = 2) {
                            do {
                                LogUtils.e(WeixinCodeActivity.this.TAG, "解析后的字符串:" + str);
                                localMessage.obj = str;
                                WeixinCodeActivity.this.handler.sendMessage(localMessage);
                                return;
                                if ((!WeixinCodeActivity.this.paytype.equals("6")) && (!WeixinCodeActivity.this.paytype.equals("7")))
                                    break;
                                localMessage.what = 0;
                            }
                            while ((!"18".equals(WeixinCodeActivity.this.paytype)) && (!"19".equals(WeixinCodeActivity.this.paytype)) && (!"20".equals(WeixinCodeActivity.this.paytype)) && (!"21".equals(WeixinCodeActivity.this.paytype)) && (!"22".equals(WeixinCodeActivity.this.paytype)) && (!"23".equals(WeixinCodeActivity.this.paytype)) && (!"24".equals(WeixinCodeActivity.this.paytype)) && (!"25".equals(WeixinCodeActivity.this.paytype)));
                            switch (WeixinCodeActivity.this.mPayTypeBean.getResolveType()) {
                                case 1:
                                case 2:
                                case 3:
                            }
                        }
                    } catch (Exception localException) {
                        while (true) {
                            localMessage.what = 1;
                            localException.printStackTrace();
                            continue;
                            if ((WeixinCodeActivity.this.paytype.equals("9")) || (WeixinCodeActivity.this.paytype.equals("10"))) {
                                localMessage.what = 0;
                            } else if ((WeixinCodeActivity.this.paytype.equals("12")) || (WeixinCodeActivity.this.paytype.equals("13"))) {
                                localMessage.what = 2;
                                if ((str.startsWith("{")) && (str.endsWith("}"))) {
                                    str = new JSONObject(str).getString("r_data");
                                    if ((str != null) && (str.length() > 0))
                                        localMessage.what = 2;
                                    else
                                        localMessage.what = 1;
                                }
                            } else if ((WeixinCodeActivity.this.paytype.equals("14")) || (WeixinCodeActivity.this.paytype.equals("15"))) {
                                localMessage.what = 2;
                            } else if (WeixinCodeActivity.this.paytype.equals("16")) {
                                localMessage.what = 2;
                            } else if (WeixinCodeActivity.this.paytype.equals("17")) {
                                localMessage.what = 3;
                                continue;
                                localMessage.what = 3;
                                continue;
                                localMessage.what = 4;
                            }
                        }
                    }
                }
            }
                    .start();
            return;
            setTitle(8, 0, 2130837809, "支付宝充值", 0, 8, 8, 0, true);
            this.tv_title.setText("支付宝支付扫码信息:");
            this.tv_miaoshu.setText(2131296497);
        }
    }

    protected void onPause() {
        super.onPause();
    }

    protected void onResume() {
        super.onResume();
    }

    @SuppressLint({"NewApi"})
    public void setTitle(int paramInt1, int paramInt2, int paramInt3, String paramString, int paramInt4, int paramInt5, int paramInt6, int paramInt7, boolean paramBoolean) {
        View localView = findViewById(2131099716);
        if (paramBoolean)
            localView.setVisibility(0);
        while (true) {
            ((TextView) localView.findViewById(2131099701)).setText(paramString);
            ((TextView) localView.findViewById(2131099700)).setVisibility(paramInt1);
            ImageView localImageView = (ImageView) localView.findViewById(2131099699);
            localImageView.setVisibility(paramInt2);
            localImageView.setOnClickListener(this.onClickListener);
            localImageView.setImageResource(paramInt3);
            TextView localTextView = (TextView) localView.findViewById(2131099702);
            localTextView.setVisibility(paramInt5);
            localTextView.setOnClickListener(this.onClickListener);
            this.iv_title_right = ((ImageView) localView.findViewById(2131099704));
            this.iv_title_right.setVisibility(paramInt6);
            this.iv_title_right.setOnClickListener(this.onClickListener);
            this.iv_title_right.setImageResource(paramInt7);
            return;
            localView.setVisibility(8);
        }
    }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.tabChongZhi.WeixinCodeActivity
 * JD-Core Version:    0.6.2
 */